package com.example.exam.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.exam.entity.Topic;
import com.example.exam.entity.VO.TopicList;
import com.example.exam.entity.compound.Question;
import com.example.exam.mapper.QuestionMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author zhang
 */
@Service
public class QuestionServiceImpl extends ServiceImpl<QuestionMapper, Topic> {
    @Autowired
    private QuestionMapper questionMapper;

    @Autowired
    private OptionService optionService;
//    public Integer addQuestion(Topic topic) {
//        return questionMapper.insert(topic);
//    }

    public IPage<TopicList> getQuestion(Integer page, Integer size) {
        return questionMapper.selectQuestionList(new Page<>(page, size));
    }

    public List<Topic> getQuestionListById(List<Integer> ids) {
        QueryWrapper<Topic> queryWrapper = new QueryWrapper<>();
        queryWrapper.in("id", ids);
        queryWrapper.eq("status", 1);
        queryWrapper.select("id", "`type`", "userId", "content", "answer", "img");
        return questionMapper.selectList(queryWrapper);
    }

    public Question getQuestionById(Integer id) {
        Question question = new Question();
        question.setTopic(getById(id));
        question.setOption(optionService.getById(id));
        return question;
    }
}
